#include "IoFile.h"
#define ALTTAG _T("|A|")
CIoFile::CIoFile(void)
{
	m_file = NULL;
	m_tools = NULL;
}

CIoFile::~CIoFile(void)
{
	if (m_file)
	{
		delete m_file; m_file = NULL;
	}
	if (m_tools)
	{
		delete m_tools; m_tools = NULL;
	}
}


BOOLEAN CIoFile::OutPutData( string value)
{
	string str , s;
	if (m_file==NULL)
	{
		m_file = new ofstream;
		m_file->open( m_filename);
	}
	str = m_format;
	str = m_tools->replace_all( str , XVALUE ,  value );
	TCHAR tmp[10];
	_itoa( m_httpurl->count , tmp, 10);
	s = string( tmp ) +  _T(":") +m_httpurl->title + _T("\r\n") + m_httpurl->url + _T("\r\n") + string(m_httpurl->m_szURL);
	str = m_tools->replace_all( str , ALTTAG ,  s );
	*m_file << str << endl;
	return TRUE;
}
VOID CIoFile::SetOutFile( LPCTSTR sFileName )
{
	m_filename = sFileName;
}

VOID CIoFile::SetOutFormat( string value)
{
	if (value.length()==0)
	{
		exit(0);
	}else{
		m_format = value;
	}
}